import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// 引入svg需要用到的插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'

import VueDevTools from 'vite-plugin-vue-devtools'

// mock插件提供方法
import { viteMockServe } from 'vite-plugin-mock'

export default defineConfig((command) => {
  return {
    plugins: [
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        symbolId: 'icon-[dir]-[name]',
      }),
      viteMockServe({
        mockPath: './mock',
        // localEnabled: command === 'serve', // 保证开发阶段可以使用mock接口
        localEnabled: true
      }),
      VueDevTools(),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src")
      }
    },
    // 配置sass全局变量
    css: {
      preprocessorOptions: { 
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";'
        }
      }
    }
  }
})
